﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;

namespace Vit.Mvc.Results
{
    public class ImageResult : ActionResult
    {
        private byte[] bytes;

        public ImageResult(byte[] bytes)
        {
            this.bytes = bytes;
        }

        public override void ExecuteResult(ControllerContext context)
        {
            MemoryStream stream = new MemoryStream(this.bytes);
            Bitmap img = new Bitmap(stream);
            context.HttpContext.Response.ContentType = "image/jpeg";
            img.Save(context.HttpContext.Response.OutputStream, ImageFormat.Jpeg);
        }
    }
}
